package main

import (
	"fmt"
	"net"
)

func main() {
	//“连接”服务端
	conn, err := net.Dial("udp", "127.0.0.1:8089")
	if err != nil {
		fmt.Println("Dial err:", err)
		return
	}
	defer conn.Close()
	//向服务端发送消息
	conn.Write([]byte("你好，我是用UDP的客户端"))
	buf := make([]byte, 1024)
	n, err := conn.Read(buf)
	if err != nil {
		fmt.Println("Read err:", err)
		return
	}
	fmt.Println("服务器发来：", string(buf[:n]))
}
